package com.rattsoftware.server.serviceImpl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rattsoftware.server.admin.model.Room;
import com.rattsoftware.server.admin.model.exceptions.RattsSecurityException;
import com.rattsoftware.server.admin.model.paging.PagingLoadConfig;
import com.rattsoftware.server.admin.model.paging.PagingLoadResult;
import com.rattsoftware.server.dao.RoomDAO;
import com.rattsoftware.server.service.RoomService;

@Service("roomService")
@Transactional
public class RoomServiceImpl implements RoomService{

	@Autowired
	private RoomDAO roomDAO;
	private Logger log = LoggerFactory.getLogger(RoomServiceImpl.class);
	
	@Override
	public void deleteRoom(Room room) throws RattsSecurityException {
		log.debug("Deleting room with number " + room.getRoomNumber());
		roomDAO.deleteRoom(room);
	}

	@Override
	public PagingLoadResult<Room> getRoomList(
			PagingLoadConfig pagingLoadConfig) throws RattsSecurityException {
		return roomDAO.getRoomList(pagingLoadConfig);
	}

	@Override
	public Room getRoomViaRoomId(int roomId) throws RattsSecurityException {
		return roomDAO.getRoomViaRoomId(roomId);
	}

	@Override
	public Room getRoomViaRoomNo(int roomNo) throws RattsSecurityException {
		return roomDAO.getRoomViaRoomNo(roomNo);
	}

	@Override
	public List<Room> getRooms() throws RattsSecurityException {
		return roomDAO.getRooms();
	}

	@Override
	public void saveRoom(Room room) throws RattsSecurityException {
		roomDAO.saveRoom(room);
	}

	@Override
	public void saveRooms(List<Room> rooms) throws RattsSecurityException {
		for (Room room : rooms) {
			saveRoom(room);
		}
	}

}
